/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.edu.fanor.entidades;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author JOSUÉ
 */
@Entity
@Table(name = "midia", catalog = "video_locadora", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Midia.findAll", query = "SELECT m FROM Midia m"),
    @NamedQuery(name = "Midia.findByIdMidia", query = "SELECT m FROM Midia m WHERE m.idMidia = :idMidia"),
    @NamedQuery(name = "Midia.findByTipoMidia", query = "SELECT m FROM Midia m WHERE m.tipoMidia = :tipoMidia")})
public class Midia implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_midia", nullable = false)
    private Long idMidia;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "tipo_midia", nullable = false, length = 45)
    private String tipoMidia;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "midiaIdMidia")
    private Collection<Filme> filmeCollection;

    public Midia() {
    }

    public Midia(Long idMidia) {
        this.idMidia = idMidia;
    }

    public Midia(Long idMidia, String tipoMidia) {
        this.idMidia = idMidia;
        this.tipoMidia = tipoMidia;
    }

    public Long getIdMidia() {
        return idMidia;
    }

    public void setIdMidia(Long idMidia) {
        this.idMidia = idMidia;
    }

    public String getTipoMidia() {
        return tipoMidia;
    }

    public void setTipoMidia(String tipoMidia) {
        this.tipoMidia = tipoMidia;
    }

    @XmlTransient
    public Collection<Filme> getFilmeCollection() {
        return filmeCollection;
    }

    public void setFilmeCollection(Collection<Filme> filmeCollection) {
        this.filmeCollection = filmeCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idMidia != null ? idMidia.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Midia)) {
            return false;
        }
        Midia other = (Midia) object;
        if ((this.idMidia == null && other.idMidia != null) || (this.idMidia != null && !this.idMidia.equals(other.idMidia))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.edu.fanor.entidades.Midia[ idMidia=" + idMidia + " ]";
    }
    
}
